#include <Thunk/ThisToCdecl.h>
#include <assert.h>

#define THUNK_MACHINE_CODE_IMPLEMENT
#include <Thunk/MachineCodeMacro.h>

namespace Thunk
{
	ThisToCdecl::~ThisToCdecl()
	{}

	ThisToCdecl::ThisToCdecl(const void *Obj,int memFunc)
		__THIS_TO__CDECL_CODES()
	{

	}

	dword_ptr ThisToCdecl::Attach(dword_ptr newObj)
	{
		dword_ptr oldObj = m_this;
		m_this = newObj;
		return oldObj;
	}

	void ThisToCdecl::SetOffset(dword dst)
	{
		m_memFunc = dst - Helper::PointerToInt32(&CALL) - (sizeof(CALL)+sizeof(m_memFunc));
	}

	dword ThisToCdecl::GetDST()
	{
		return m_memFunc + Helper::PointerToInt32(&CALL) - (sizeof(CALL)+sizeof(m_memFunc));
	}

	dword ThisToCdecl::Attach(dword newFunc)
	{
		dword oldFunc = GetDST();
		SetOffset(newFunc);
		return oldFunc;
	}
}
